#pragma once

class CTimerManager;
class CReconnecter
{
public:
	CReconnecter( HWND hWnd );
	virtual ~CReconnecter(void);

public:
	virtual void Determine( ISockMsg* pMsg );
	void OnTimer( int nID );

protected:
	void Reconnect( int nReason );
	
protected:
	typedef std::auto_ptr<CTimerManager> AP_TIMER;
	AP_TIMER	m_apTimer;
	bool		m_bConnected;
	DWORD		m_dwLastPack;
	HWND		m_hWnd;
	UINT		m_nTimedOut;
};



class CTimerManager
{
public:
	CTimerManager( HWND hWnd )
		: m_nReconnElapse( g_nInterval*SECOND )
		, m_nCheckElapse( 1*1000 )
		, m_hWnd( hWnd )
	{
		;
	}

	void SetReconnTimer( void );
	void SetCheckTimer( void );

	void KillReconnTimer( void );
	void KillCheckTimer( void );

	const static int	SECOND = 1000;
	const static UINT_PTR	TimerIDReconn = 99;
	const static UINT_PTR	TimerIDCheck = 88;

	UINT		m_nReconnElapse;
	UINT		m_nCheckElapse;

	HWND		m_hWnd;
};

inline void CTimerManager::SetReconnTimer( void )
{
	ASSERT( ::IsWindow(m_hWnd) );
	SetTimer( m_hWnd, TimerIDReconn, m_nReconnElapse, NULL );
}

inline void CTimerManager::SetCheckTimer( void )
{
	ASSERT( ::IsWindow(m_hWnd) );
	SetTimer( m_hWnd, TimerIDCheck, m_nCheckElapse, NULL );
}

inline void CTimerManager::KillReconnTimer( void )
{
	KillTimer( m_hWnd, TimerIDReconn );
}

inline void CTimerManager::KillCheckTimer( void )
{
	KillTimer( m_hWnd, TimerIDCheck );
}
